import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.utils import shuffle
from sklearn import ensemble, tree, linear_model
from sklearn.cross_validation import train_test_split, cross_val_score
from sklearn.metrics import r2_score, mean_squared_error
housesList=[]
columnsname=[]
houses=pd.read_csv('train.csv')
dictColumns=dict(houses.dtypes)
for item in dictColumns.items():
    collist=[]
    col=houses[item[0]]
    label2int = {}
    int2label = {}
    columnsname.append(item[0])
    if item[1]=="object":
        for idx, itr in enumerate(set(col)):
            label2int[itr] = idx
            int2label[idx] = itr
        for colitem in col:
            collist.append(label2int[colitem])
    elif item[1]=="int64":
        for colitem in col:
            if colitem=="NA":
                colitem=0
            collist.append(colitem)
    else:
        for colitem in col:
            if colitem == "NA":
                colitem = 0
            collist.append(colitem)

    housesList.append(collist)
print(housesList)
dic={}
for item in range(len(housesList)):
    dic[columnsname[item]]=housesList[item]
save = pd.DataFrame(dic)
#save = pd.DataFrame(data=result,columns=["id","class"])
save.to_csv('result2.csv',index=False)

SalePrice=list(houses["Alley"])

housesLst=[]
#for row in houses:

label2int = {}
int2label = {}
for idx, itr in enumerate(set(SalePrice)):
    label2int[itr] = idx
    int2label[idx] = itr
print(label2int)
'''
MiscVal=list(houses["MiscVal"])
MSSubClass=list(houses["MSSubClass"])
plt.scatter(MiscVal[:], SalePrice[:])
plt.title("MiscVal_SalePrice")
plt.axis("equal")
plt.show()
print(SalePrice)
plt.scatter(MSSubClass[:], SalePrice[:])
plt.title("MSSubClass_SalePrice")
plt.axis("equal")
plt.show()
print(SalePrice)
'''


